//
// Created by 喵喵乐 on 2023/4/9.
//

#ifndef CMAKECXX_ARRAY_2_H
#define CMAKECXX_ARRAY_2_H

#include <cstddef>
#include <iostream>

template<class T>
class Array_2 {
    enum {
        INT = 10
    };

    T *data;

    size_t capactiy;

    size_t count;
public:
    Array_2() : count(0), capactiy(new T[capactiy = INT]) {};

    ~Array_2() { delete[]data; }

    void push_back(const T &t) {

        if(count == capactiy){
            size_t newCap = 2 * capactiy;

            T *newData = new T[newCap];

            for (int i = 0; i < count; ++i) {
                newData[i] = data[i];
            }
            delete[] data;
            data = newData;

        }
    }
};

#endif //CMAKECXX_ARRAY_2_H
